<?php
declare (strict_types=1);

namespace app\common\model\activity\lottery;

use app\common\model\BaseModel;

/**
 *
 * Class LuckPrizeDao
 * @package app\model\activity\lottery
 */
class LuckPrize extends BaseModel
{

    /**
     * @return string
     * @author: fupeng
     * @day: 2024/3/26
     */
    public static function tablePk(): string
    {
        return 'id';
    }

    /**
     * @return string
     * @author: fupeng
     * @day: 2024/3/26
     */
    public static function tableName(): string
    {
        return 'luck_prize';
    }


    /**
     * 关联抽奖
     * @return \think\model\relation\HasOne
     */
    public function lottery()
    {
        return $this->hasOne(LuckLottery::class, 'id', 'lottery_id');
    }

    /**
     * 抽奖id搜索器
     * @param $query Model
     * @param $value
     */
    public function searchLotteryIdAttr($query, $value)
    {
        if ($value) $query->where('lottery_id', $value);
    }

    /**
     * 奖品类型搜索器
     * @param $query Model
     * @param $value
     */
    public function searchTypeAttr($query, $value)
    {
        if ($value) $query->where('type', $value);
    }

    /**
     * 状态搜索器
     * @param $query Model
     * @param $value
     */
    public function searchStatusAttr($query, $value)
    {
        if ($value !== '') $query->where('status', $value);
    }

    /**
     * 是否删除搜索器
     * @param $query Model
     * @param $value
     */
    public function searchIsDelAttr($query, $value)
    {
        if ($value !== '') $query->where('is_del', $value);
    }
}
